Retrieving the MPV Tidy Dataset
mpv_data =
read_csv("./data/mpv_final.csv")
## Parsed with column specification:
## cols(
## age = col_double(),
## gender = col_character(),
## race = col_character(),
## police_dept = col_character(),
## disposition = col_character(),
## year = col_double(),
## month = col_double(),
## day = col_double(),
## city = col_character(),
## state = col_character(),
## county = col_character(),
## cause_of_death = col_character(),
## criminal_charges = col_character(),
## symptoms_of_mental_illness = col_character(),
## lat = col_double(),
## lng = col_double()
## )
Year Leaflet – with city and police dept in the label
pal <- colorNumeric(
palette = "viridis",
domain = mpv_data$year)
mpv_data %>%
drop_na() %>%
mutate(
lab = str_c("City: ", city, "<br>Police Department: ", police_dept)) %>%
leaflet() %>%
addTiles() %>%
setView(-98.483330, 38.712046, zoom = 4) %>%
addLegend("bottomright", pal = pal,
values = ~year,
title = "Year",
labFormat = labelFormat(big.mark = ""),
opacity = 1) %>%
addCircleMarkers(
~lng, ~lat,
color = ~pal(year),
radius = 0.5,
popup = ~lab)
Age Leaflet – with symptoms of mental illness and whether officer was charged as label
pal <- colorNumeric(
palette = "viridis",
domain = mpv_data$age)
mpv_data %>%
drop_na() %>%
mutate(
lab = str_c("Age: ", age,
"<br>Symptoms of Mental Illness: ", symptoms_of_mental_illness,
"<br>Charges on the Police: ", criminal_charges)) %>%
leaflet() %>%
addTiles() %>%
setView(-98.483330, 38.712046, zoom = 4) %>%
addLegend("bottomright", pal = pal,
values = ~age,
title = "Age",
opacity = 1) %>%
addCircleMarkers(
~lng, ~lat,
color = ~pal(age),
radius = 0.5,
popup = ~lab)
USA data
usa_protest = read_csv("./data/usa_tidy.csv")
## Parsed with column specification:
## cols(
## year = col_double(),
## month = col_double(),
## day = col_double(),
## event_type = col_character(),
## sub_event_type = col_character(),
## state = col_character(),
## county = col_character(),
## city = col_character(),
## latitude = col_double(),
## longitude = col_double(),
## fatalities = col_double()
## )
pal <- colorNumeric(
palette = "viridis",
domain = usa_protest$fatalities)
usa_protest %>%
mutate(
lab = str_c("City: ", usa_protest$city, "<br>Type of Protest: ", usa_protest$event_type)) %>%
leaflet() %>%
addTiles() %>%
setView(-98.483330, 38.712046, zoom = 4) %>%
addLegend("bottomright", pal = pal,
values = usa_protest$fatalities,
title = "Fatalities",
labFormat = labelFormat(big.mark = ""),
opacity = 1) %>%
addCircleMarkers(
~longitude, ~latitude,
color = ~pal(usa_protest$fatalities),
radius = 0.5,
popup = ~lab)
pal <- colorNumeric(
palette = "viridis",
domain = usa_protest$month)
usa_protest %>%
mutate(
lab = str_c("City: ", usa_protest$city, "<br>Type of Protest: ", usa_protest$event_type)) %>%
leaflet() %>%
addTiles() %>%
setView(-98.483330, 38.712046, zoom = 4) %>%
addLegend("bottomright", pal = pal,
values = usa_protest$month,
title = "Month",
labFormat = labelFormat(big.mark = ""),
opacity = 1) %>%
addCircleMarkers(
~longitude, ~latitude,
color = ~pal(usa_protest$month),
radius = 0.5,
popup = ~lab)
ACS Income maps
Police Killings by Income Class
build_df =
read_csv("./data/build_df.csv") %>%
mutate(
income_class = fct_relevel(income_class, "Very High", "High", "Middle", "Low", "Very Low")
)
## Parsed with column specification:
## cols(
## .default = col_double(),
## gender = col_character(),
## race = col_character(),
## police_dept = col_character(),
## disposition = col_character(),
## city = col_character(),
## state = col_character(),
## county = col_character(),
## cause_of_death = col_character(),
## criminal_charges = col_character(),
## symptoms_of_mental_illness = col_character(),
## state_name = col_character(),
## id = col_character(),
## income_class = col_character()
## )
## See spec(...) for full column specifications.
factpal <- colorFactor("RdYlGn", build_df %>% pull(income_class))
build_df %>%
drop_na() %>%
mutate(
pop = str_c("Cause of Death: ", cause_of_death,
"<br>Police Dept: ", police_dept,
"<br>Age: ", age,
"<br>Year: ", year,
"<br>Symptoms of Mental Illness: ", symptoms_of_mental_illness)) %>%
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addLegend("bottomright", pal = factpal,
values = ~as.factor(income_class),
title = "Income Class",
labFormat = labelFormat(big.mark = ""),
opacity = 1) %>%
addCircleMarkers(
~lng, ~lat,
color = ~factpal(income_class),
radius = 0.5,
popup = ~pop
)
Protest Data by Income Class
protest_income_df =
read_csv("./data/protest_income_df.csv") %>%
mutate(
income_class = fct_relevel(income_class, "Very High", "High", "Middle", "Low", "Very Low")
)
## Parsed with column specification:
## cols(
## .default = col_double(),
## event_type = col_character(),
## sub_event_type = col_character(),
## state = col_character(),
## county = col_character(),
## city = col_character(),
## id = col_character(),
## income_class = col_character()
## )
## See spec(...) for full column specifications.
quantile(protest_income_df$disparity_value, na.rm = TRUE)
## 0% 25% 50% 75% 100%
## 6665 19599 23664 30534 76802
factpal2 <- colorFactor("BuGn", protest_income_df %>% pull(income_class))
protest_income_df %>%
drop_na() %>%
mutate(
pop1 = str_c("City: ", city, "<br>Event Type: ",
sub_event_type, "<br>Year: ", year, "<br>Fatalities: ", fatalities)) %>%
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addLegend("bottomright", pal = factpal2,
values = ~as.factor(income_class),
title = "Income Class",
labFormat = labelFormat(big.mark = ""),
opacity = 1) %>%
addCircleMarkers(
~longitude, ~latitude,
color = ~factpal2(income_class),
radius = 0.5,
popup = ~pop1
)
Police Killings by Disparity Score
build_df =
read_csv("./data/build_df.csv")
## Parsed with column specification:
## cols(
## .default = col_double(),
## gender = col_character(),
## race = col_character(),
## police_dept = col_character(),
## disposition = col_character(),
## city = col_character(),
## state = col_character(),
## county = col_character(),
## cause_of_death = col_character(),
## criminal_charges = col_character(),
## symptoms_of_mental_illness = col_character(),
## state_name = col_character(),
## id = col_character(),
## income_class = col_character()
## )
## See spec(...) for full column specifications.
valpal <- colorNumeric("RdYlGn", build_df %>% pull(disparity_value))
build_df %>%
drop_na() %>%
mutate(
pop = str_c("Cause of Death: ", cause_of_death,
"<br>Police Dept: ", police_dept,
"<br>Age: ", age,
"<br>Year: ", year,
"<br>Symptoms of Mental Illness: ", symptoms_of_mental_illness)) %>%
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addLegend("bottomright", pal = valpal,
values = ~disparity_value,
title = "Income Disparity",
labFormat = labelFormat(big.mark = ""),
opacity = 1) %>%
addCircleMarkers(
~lng, ~lat,
color = ~valpal(disparity_value),
radius = 0.5,
popup = ~pop
)
Protest Data by Disparity Score
protest_income_df =
read_csv("./data/protest_income_df.csv") %>%
mutate(
income_class = fct_relevel(income_class, "Very High", "High", "Middle", "Low", "Very Low")
) %>%
mutate(
disparity_level =
case_when(
disparity_value < 20000 ~ "Very Low",
disparity_value %in% 20000:24999 ~ "Low",
disparity_value %in% 25000:30000 ~ "Middle",
disparity_value %in% 30000:40000 ~ "High",
disparity_value > 40000 ~ "Very High"
),
disparity_level = fct_relevel(income_class, "Very Low", "Low", "Middle", "High", "Very High")
)
## Parsed with column specification:
## cols(
## .default = col_double(),
## event_type = col_character(),
## sub_event_type = col_character(),
## state = col_character(),
## county = col_character(),
## city = col_character(),
## id = col_character(),
## income_class = col_character()
## )
## See spec(...) for full column specifications.
factpal3 <- colorFactor("magma", protest_income_df %>% pull(disparity_level))
protest_income_df %>%
drop_na() %>%
mutate(
pop2 = str_c("City: ", city, "<br>Event Type: ",
sub_event_type, "<br>Year: ", year, "<br>Fatalities: ", fatalities)) %>%
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addLegend("bottomright", pal = factpal3,
values = ~disparity_level,
title = "Income Disparity",
labFormat = labelFormat(big.mark = ""),
opacity = 1) %>%
addCircleMarkers(
~longitude, ~latitude,
color = ~factpal3(disparity_level),
radius = 0.5,
popup = ~pop2
)